#include <stdlib.h>
#include "gus2_config.h"
#include "bytearray.h"
/*************************** porting for rx message **********************************/
#if GUS2_ENABLE_RX
static int _lock = 0;
void msg_queue_lock()
{
    while (_lock == 1) {
    };
    _lock = 1;
}
void msg_queue_unlock()
{
    _lock = 0;
}
bytearray_t* rx_buff_get_bytearray(int size)
{
    return byte_array_create(size);
}

void rx_buff_post_bytearray(bytearray_t* ba)
{
    byte_array_free(ba);
}
#endif 

/*************************** porting for send data **********************************/
#if 1
#include "SWM190.h"
int write_data(unsigned char data)
{
	UART_WriteByte(UART0, data);
	while(UART_IsTXBusy(UART0));
	return 1;
}
void flush_port()
{
}
#endif 

/*************************** porting for malloc and free **********************************/
static void* _malloc(int size)
{
    return malloc(size);
}

static void _free(void* buf)
{
    free(buf);
}

void gus2_lib_init()
{
    gusConfigInit(0xAB, 0xBA, _free, _malloc);
}
